package controller

import (
	"gin_server/internal/service"
	"gin_server/pkg/response"
	"net/http"

	"github.com/gin-gonic/gin"
)

type CaptchaController struct {
	captchaService *service.CaptchaService
}

func NewCaptchaController(captchaService *service.CaptchaService) *CaptchaController {
	return &CaptchaController{
		captchaService: captchaService,
	}
}

// GenerateCaptcha 获取验证码图片
// @Summary 获取验证码图片
// @Description 返回图片base64和验证码ID
// @Tags 验证码
// @Accept json
// @Produce json
// @Success 200 {object} service.CaptchaResponse
// @Router /captcha [get]
func (c *CaptchaController) GenerateCaptcha(ctx *gin.Context) {
	// 生成验证码
	captchaResponse, err := c.captchaService.GenerateCaptcha()
	if err != nil {
		response.Error(ctx, "获取图片验证码失败: "+err.Error())
		return
	}

	// 返回验证码ID和图片base64
	ctx.JSON(http.StatusOK, captchaResponse)
}
